/*
 * @Author: szx
 * @Date: 2022-03-10 14:07:17
 * @LastEditTime: 2022-03-10 14:13:33
 * @Description:
 * @FilePath: \leetcode\1-99\3\3.js
 */
/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function (s) {
    const set = new Set();
    let res = 0;
    for (let j = 0, i = 0; j < s.length; j++) {
        while (set.has(s[j])) {
            set.delete(s[i]);
            i++;
        }
        res = Math.max(res, j - i + 1);
        set.add(s[j]);
    }
    return res;
};
console.log(lengthOfLongestSubstring('abcabcbb'));
console.log(lengthOfLongestSubstring('bbb'));
console.log(lengthOfLongestSubstring('pwwkew'));
console.log(lengthOfLongestSubstring('abccd'));
